# -*- coding: UTF-8 -*-
"""
@Time : 2022/12/5
@Author : Gloria
"""
from django.contrib import admin
from django.utils.safestring import mark_safe
from app01.models import Comment
import re

from ..templatetags.my_filter import translate_time


class CommentAdmin(admin.ModelAdmin):
    def get_content(self: Comment):
        content = self.content
        lis = re.sub(r'!\[(.*?)\]\((.*?)\)', r'<img style="width:15px; height:15px;margin: 0 5px;" src="\2" alt="\1">', content, )
        return mark_safe(lis)

    get_content.short_description = '评论内容'

    def get_create_time(self: Comment):
        create_time = translate_time(self.create_time)
        return mark_safe(create_time)

    get_create_time.short_description = '评论时间'

    list_display = ['user', get_content, 'article', get_create_time, 'comment_count']
